﻿using System.Collections.Generic;
using System.Windows.Browser;

namespace jLight
{
    public class jQueryCoordinate : jQueryObjectBase
    {
        private double _left;
        private double _top;

      
        public double Left
        {
            get
            {
                _left = (double)ScriptObject.GetProperty("left");
                return _left;
            }
            set
            {
                if (_left == value) return;
                _left = value;
                SetJavascript();
            }
        }

        public double Top
        {
            get
            {
                _top = (double)ScriptObject.GetProperty("top");
                return _top;
            }
            set
            {
                if (_top == value) return;
                _top = value;
                SetJavascript();
            }
        }
        protected override void SetProperties(Dictionary<string, object> properties)
        {
            this.Left = (double)properties["left"];
            this.Top = (double)properties["top"];
        }

        protected override void SetJavascript()
        {
            ScriptObject = (ScriptObject)HtmlPage.Window.Eval(string.Format("[{{left:{0},top:{1}}}][0]",this.Left, this.Top));
        }

        public static implicit operator jQueryCoordinate(ScriptObject m)
        {
            return new jQueryCoordinate(){ScriptObject = m};
        }
    }

    //TODO: Add most common css attributes
}